package com.nageoffer.shortlink.project.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * ClassName: MyMetaObjectHandler
 * Package:
 * Description:   数据库填充配置
 *
 * @Author:xiaohei
 * @Create 2024/6/4 20:31
 * Version 1.0
 */
@ConditionalOnBean(MyMetaObjectHandler.class)
@Component(value = "myMetaObjectHandlerByProject")
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"createTime", Date::new, Date.class);
        this.strictInsertFill(metaObject,"updateTime", Date::new, Date.class);
        this.strictInsertFill(metaObject,"delFlag",() -> 0, Integer.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject,"updateTime", Date::new, Date.class);
    }
}
